home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / toadebc.zip / EBCDIC.PAS < prev    next >
Pascal/Delphi Source File  |  1986-11-29  |  6KB  |  246 lines

  1. Program EBCDIC;   {Converts EBCDIC to ASCII}
  2.  
  3. {
  4.  
  5.      This program was developed out of a need to convert IBM mainframe
  6.      data stored in EBCDIC format into data that could easily be imported
  7.      to DBASE III and/or DBASE III+.  I used the Black Box catalog for the
  8.      code conversions from EBCDIC to ASCII.  Be sure that your data does
  9.      not contain any COMP3 or COMP fields (packed numeric).  This program
  10.      will not handle those.
  11.  
  12. }
  13.  
  14. type
  15.  
  16.   filename     = String[64];
  17.  
  18. var
  19.  
  20.   infile       : file of byte;
  21.   outfile      : text;
  22.   j            : integer;
  23.   i            : integer;
  24.   tempbyte     : byte;
  25.   e2a          : array[$00..$ff] of byte; {Array that holds EBCDIC to ASCII.}
  26.   infilename   : filename;
  27.   outfilename  : filename;
  28.  
  29. Procedure Wind(Left,Top,Right,Bottom : Integer);
  30.  
  31.   Procedure Box(Left,Top,Right,Bottom : Integer);
  32.  
  33.     var
  34.       i : Integer;
  35.  
  36.     begin
  37.       GotoXY(Left-1,Top-1);
  38.       Write('╔');
  39.       GotoXY(Right+1,Top-1);
  40.       Write('╗');
  41.       GotoXY(Left-1,Bottom+1);
  42.       Write('╚');
  43.       GotoXY(Right+1,Bottom+1);
  44.       Write('╝');
  45.       for i := Top to Bottom do begin
  46.         GotoXY(Left-1,i);
  47.         Write('║');
  48.         GotoXY(Right+1,i);
  49.         Write('║');
  50.         end;
  51.       for i := Left to Right do begin
  52.         GotoXY(i,Top-1);
  53.         Write('═');
  54.         GotoXY(i,Bottom+1);
  55.         Write('═');
  56.         end;
  57.     end;
  58.  
  59.   begin
  60.     Box(Left,Top,Right,Bottom);
  61.     Window(Left,Top,Right,Bottom);
  62.     Clrscr;
  63.   end;
  64.  
  65. Procedure Initialize;   {Load up the Array for EBCDIC to ASCII conversion.}
  66.  
  67.   var
  68.     i            : integer;
  69.  
  70.   begin
  71.        for i := 0 to 255 do e2a[i] := 32; {Initialize the whole array.}
  72.        e2a[$C1]   := 65;                  {Load individual character values.}
  73.        e2a[$C2]   := 66;                  {Index value is EBCDIC value.}
  74.        e2a[$C3]   := 67;
  75.        e2a[$C4]   := 68;
  76.        e2a[$C5]   := 69;
  77.        e2a[$C6]   := 70;
  78.        e2a[$C7]   := 71;
  79.        e2a[$C8]   := 72;
  80.        e2a[$C9]   := 73;
  81.        e2a[$D1]   := 74;
  82.        e2a[$D2]   := 75;
  83.        e2a[$D3]   := 76;
  84.        e2a[$D4]   := 77;
  85.        e2a[$D5]   := 78;
  86.        e2a[$D6]   := 79;
  87.        e2a[$D7]   := 80;
  88.        e2a[$D8]   := 81;
  89.        e2a[$D9]   := 82;
  90.        e2a[$E2]   := 83;
  91.        e2a[$E3]   := 84;
  92.        e2a[$E4]   := 85;
  93.        e2a[$E5]   := 86;
  94.        e2a[$E6]   := 87;
  95.        e2a[$E7]   := 88;
  96.        e2a[$E8]   := 89;
  97.        e2a[$E9]   := 90;
  98.        e2a[$81]   := 97;
  99.        e2a[$82]   := 98;
  100.        e2a[$83]   := 99;
  101.        e2a[$84]   := 100;
  102.        e2a[$85]   := 101;
  103.        e2a[$86]   := 102;
  104.        e2a[$87]   := 103;
  105.        e2a[$88]   := 104;
  106.        e2a[$89]   := 105;
  107.        e2a[$91]   := 106;
  108.        e2a[$92]   := 107;
  109.        e2a[$93]   := 108;
  110.        e2a[$94]   := 109;
  111.        e2a[$95]   := 110;
  112.        e2a[$96]   := 111;
  113.        e2a[$97]   := 112;
  114.        e2a[$98]   := 113;
  115.        e2a[$99]   := 114;
  116.        e2a[$A2]   := 115;
  117.        e2a[$A3]   := 116;
  118.        e2a[$A4]   := 117;
  119.        e2a[$A5]   := 118;
  120.        e2a[$A6]   := 119;
  121.        e2a[$A7]   := 120;
  122.        e2a[$A8]   := 121;
  123.        e2a[$A9]   := 122;
  124.        e2a[$F0]   := 48;
  125.        e2a[$F1]   := 49;
  126.        e2a[$F2]   := 50;
  127.        e2a[$F3]   := 51;
  128.        e2a[$F4]   := 52;
  129.        e2a[$F5]   := 53;
  130.        e2a[$F6]   := 54;
  131.        e2a[$F7]   := 55;
  132.        e2a[$F8]   := 56;
  133.        e2a[$F9]   := 57;
  134.        e2a[$40]   := 32;
  135.        e2a[$5A]   := 33;
  136.        e2a[$7F]   := 34;
  137.        e2a[$7B]   := 35;
  138.        e2a[$5B]   := 36;
  139.        e2a[$6C]   := 37;
  140.        e2a[$50]   := 38;
  141.        e2a[$7D]   := 39;
  142.        e2a[$4D]   := 40;
  143.        e2a[$5D]   := 41;
  144.        e2a[$5C]   := 42;
  145.        e2a[$4E]   := 43;
  146.        e2a[$6B]   := 44;
  147.        e2a[$60]   := 45;
  148.        e2a[$4B]   := 46;
  149.        e2a[$61]   := 47;
  150.        e2a[$7A]   := 58;
  151.        e2a[$5E]   := 59;
  152.        e2a[$4C]   := 60;
  153.        e2a[$7E]   := 61;
  154.        e2a[$6E]   := 62;
  155.        e2a[$6F]   := 63;
  156.        e2a[$7C]   := 64;
  157.        e2a[$E0]   := 92;
  158.        e2a[$6D]   := 95;
  159.        e2a[$C0]   := 123;
  160.        e2a[$6A]   := 124;
  161.        e2a[$D0]   := 125;
  162.        e2a[$A1]   := 126;
  163.        e2a[$4A]   := 155;
  164.        e2a[$5F]   := 191;
  165.        e2a[$2E]   := 6;
  166.        e2a[$2F]   := 7;
  167.        e2a[$16]   := 8;
  168.        e2a[$18]   := 24;
  169.        e2a[$0D]   := 13;
  170.        e2a[$11]   := 17;
  171.        e2a[$12]   := 18;
  172.        e2a[$13]   := 19;
  173.        e2a[$3C]   := 20;
  174.        e2a[$07]   := 127;
  175.        e2a[$10]   := 16;
  176.        e2a[$19]   := 25;
  177.        e2a[$2D]   := 5;
  178.        e2a[$37]   := 4;
  179.        e2a[$27]   := 27;
  180.        e2a[$26]   := 23;
  181.        e2a[$03]   := 3;
  182.        e2a[$0C]   := 12;
  183.        e2a[$22]   := 28;
  184.        e2a[$05]   := 9;
  185.        e2a[$25]   := 10;
  186.        e2a[$3D]   := 21;
  187.        e2a[$00]   := 0;
  188.        e2a[$35]   := 30;
  189.        e2a[$0F]   := 15;
  190.        e2a[$0E]   := 14;
  191.        e2a[$01]   := 1;
  192.        e2a[$02]   := 2;
  193.        e2a[$32]   := 22;
  194.        e2a[$0B]   := 11;
  195.   end;
  196.  
  197. Procedure Ebcdic(var tempbyte:byte);  {Convert a byte to ASCII.}
  198.  
  199.   begin
  200.     tempbyte := e2a[tempbyte];
  201.   end;
  202.  
  203.  
  204.  
  205. {Here is the main part of the program.}
  206.  
  207.  
  208. begin
  209.  
  210.      Initialize;
  211.      ClrScr;
  212.      Wind(6,2,74,11);
  213.      Writeln('Author - Lou Seigal     Date: 11/29/86');
  214.      Writeln;
  215.      Writeln('  This program will convert EBCDIC data to an ASCII text file');
  216.      Writeln('conforming to SDF format for importation into DBASE III or');
  217.      Writeln('DBASE III+.');
  218.      Writeln('  You must know the structure of your source data file so you can');
  219.      Writeln('build the DBASE file properly.');
  220.      Window(1,1,80,25);
  221.      Wind(2,14,79,16);
  222.      Write('     Enter source file name : ');
  223.      Readln(infilename);
  224.      Write('Enter destination file name : ');
  225.      Readln(outfilename);
  226.      Window(1,1,80,25);
  227.      Wind(2,19,79,23);
  228.      Writeln('                            Converted Data');
  229.      Window(2,20,79,23);
  230.      Assign(infile,infilename);
  231.      Reset(infile);
  232.      Assign(outfile,outfilename);
  233.      Rewrite(outfile);
  234.      while not eof(infile) do begin
  235.        read(infile,tempbyte);
  236.        ebcdic(tempbyte);
  237.        write(chr(tempbyte));
  238.        write(outfile,chr(tempbyte));
  239.      end;
  240.      Close(infile);
  241.      Close(outfile);
  242.      Window(1,1,80,25);
  243.      ClrScr;
  244.      Writeln('I am done converting ',infilename,' to ',outfilename,'.');
  245. end.
  246.